package com.example.websocketserver.pojo;

import lombok.AllArgsConstructor;
import org.apache.commons.lang.StringUtils;

/**
 * @author liulei
 * @version 1.0
 */
@AllArgsConstructor
public enum WebSocketModuleEnum {
    /**
     * 消息推送模块划分
     */
    DEVICE("device", "/topic/device."),
    ALARM("alarm", "/topic/alarm."),
    SCENE("scene", "/topic/scene."),
    ;

    private String module;

    private String topicPrefix;

    /**
     * 获取完整topic名称
     */
    public String getTopicName(String value) {
        return this.topicPrefix + value;
    }

    /**
     * 根据module获取枚举
     */
    public static WebSocketModuleEnum getByModule(String module) {
        if (StringUtils.isNotEmpty(module)) {
            WebSocketModuleEnum[] values = values();
            for (WebSocketModuleEnum en : values) {
                if (en.module.equals(module)) {
                    return en;
                }
            }
        }
        throw new RuntimeException("消息推送模块解析异常");
    }
}
